package cn.edu.neusoft.mall.Dao.impl;

import cn.edu.neusoft.framework.db.JDBCTemplate;
import cn.edu.neusoft.framework.db.RowMapper;
import cn.edu.neusoft.mall.Dao.subscribeDao;
import cn.edu.neusoft.mall.entity.Comment;
import cn.edu.neusoft.mall.entity.subscribe;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class subscribeDaoImpl implements subscribeDao {
    RowMapper<subscribe> rowMapper=new RowMapper<subscribe>() {
        @Override
        public subscribe mapRow(ResultSet rs, int rowNum) throws SQLException {
            subscribe Subscribe=new subscribe();
            Subscribe.setUser_id(rs.getInt("user_id"));
            Subscribe.setPet_id(rs.getString("pet_id"));
            Subscribe.setTime(rs.getTimestamp("timestamp"));
            return Subscribe;
        }
    };
    @Override
    public List<subscribe> getSubscribeList() {
        String sql="select * from subscribe";
        return JDBCTemplate.query(sql,rowMapper,null);
    }

    @Override
    public int addSubscribe(subscribe subscribe) {
        String sql="insert into subscribe(user_id, pet_id,timestamp) values(?,?,?)";
        return JDBCTemplate.update(sql,subscribe.getUser_id(),subscribe.getPet_id(),subscribe.getTime());
    }
}
